package com.tistory.commons.utils;

import java.io.File;
import java.util.List;
import java.util.ArrayList;


public class FileUploadN
{
    public static List multiFileUpload(List<File> uploadFiles,List<String> uploadFileNames,String filePath) throws Exception
    {
        if(uploadFiles.size() > 0)
        {
            List<String> listAttFile = new ArrayList();
            
            for(int i = 0; i<uploadFiles.size(); i++)
            {
                File file = uploadFiles.get(i);
                String uploadFileName = uploadFileNames.get(i);
                String attFile = FileUploadUtil.uploadFile(file, filePath, i+"_"+uploadFileName);
                listAttFile.add(attFile);
            }
            
            return listAttFile;
        }
        
        return null;
    }

    public static List<String> multiFileUploadLt(List<File> uploadFiles,List<String> uploadFileNames,String filePath) throws Exception
    {
        List<String> fNmLt  = null;

        if(uploadFiles.size() > 0)
        {
            fNmLt   = new ArrayList<String>();

            for(int i = 0; i<uploadFiles.size(); i++)
            {
                File file = uploadFiles.get(i);
                String uploadFileName = delPath(uploadFileNames.get(i));

                String  ext = "";
                if(uploadFileName.lastIndexOf(".")>0)
                    ext = uploadFileName.substring(uploadFileName.lastIndexOf("."));

                String  newName = FileUploadUtil.uploadFile(file, filePath, StringUtil.LPAD(""+(i+1), 10, '0')+ext);

                fNmLt.add(delPath(newName));
            }
        }

        return fNmLt;
    }

    public static List<String> multiImageFileUploadLt(List<File> uploadFiles, List<String> uploadFileNames, String filePath) throws Exception
    {
        List<String> fNmLt  = null;

        if(uploadFiles.size() > 0)
        {
            fNmLt   = new ArrayList<String>();

            for(int i = 0; i<uploadFiles.size(); i++)
            {
                File file = uploadFiles.get(i);
                String uploadFileName = delPath(uploadFileNames.get(i));

                String  ext = "";
                if(uploadFileName.lastIndexOf(".")>0)
                    ext = uploadFileName.substring(uploadFileName.lastIndexOf("."));

                String  newName = FileUploadUtil.uploadFile(file, filePath, StringUtil.LPAD(""+(i+1), 10, '0')+ext);
                fNmLt.add(delPath(newName));


                try
                {
//System.out.println();
//System.out.println();
//System.out.println();
//System.out.println();
//System.out.println("====================================================================================");
String TCAST_IMG_EFFECT[] = {"/data/img/img_filter/icon/104/round_mask.png","/data/img/img_filter/icon/104/filter_merge.png","/data/img/img_filter/icon/104/drop_shadow.png"};
int    TCAST_IMG_EXPAND[] = {4,4,18,18};
String TCAST_IMG_TYPE     = "jpge";
int    TCAST_IMG_WIDTH    = 82;
int    TCAST_IMG_HEIGHT   = 82;
String TCAST_DIR_PATH     = "thumbnail_82x82_";

//System.out.println("filePath:"+filePath+delPath(newName));
//System.out.println(filePath+TCAST_DIR_PATH+delPath(newName));

//"C:\\data\\img\\web\\tcast\\20090707"+delPath(newName),
//                    ImageUtil.setImgEffect(filePath+delPath(newName),
//                                           filePath+TCAST_DIR_PATH+delPath(newName),
//                                           TCAST_IMG_WIDTH,
//                                           TCAST_IMG_HEIGHT,
//                                           TCAST_IMG_EFFECT,
//                                           TCAST_IMG_EXPAND,
//                                           TCAST_IMG_TYPE);
                }
                catch( Exception e )
                {
                    e.printStackTrace();
                }
            }
        }

        return fNmLt;
    }

    public static String delPath(String param)
    {
        String  rtn = param;

        if(param.indexOf("/")!=-1)
        {
            String  lt[]    = param.split("/");
            rtn = lt[lt.length-1];
        }

        if(param.indexOf("\\")!=-1)
        {
            String  lt[]    = param.split("\\\\");
            rtn = lt[lt.length-1];
        }

        return rtn;
    }

    public static void makeThumbnailImag(List<File> inputFiles,List<String> outPutFileNames,String filePath)
    {
        if(inputFiles.size() > 0)
        {
            for(int i = 0; i<inputFiles.size(); i++)
            {
                File file = inputFiles.get(i);
                String outFileName = filePath + File.separator + outPutFileNames.get(i);
                System.out.println("OutfileName[" + i + "]: " + outFileName);
//                ImageUtil.setImgScale(file, outFileName, 100, 100);
            }
        }
    }
}
